package com.yj.answer.controller;

import com.yj.answer.entity.Answer;
import com.yj.answer.service.IAnswerService;
import com.yj.answer.service.impl.AnswerServiceImpl;
import com.yj.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 题目 前端控制器
 * </p>
 *
 * @author yj
 * @since 2023-07-07
 */
@RestController
@RequestMapping("/answer")
public class AnswerController {

    @Autowired
    private IAnswerService ansiElement;

    /**
     * 作用: 随机题
     * yinj on 2023/7/7
     * @param
     * @return Result
    **/
    @RequestMapping("RandTopics/{num}")
    public Result RandTopics(@PathVariable("num") Integer num){
        List<Answer> answers = ansiElement.RandTopics(num);
        return Result.ok(answers);
    }

    /**
     * 作用: 章节
     * yinj on 2023/7/7
     * @param chapter
     * @return Result
    **/
    @RequestMapping("chapterTopics/{chapter}")
    public Result chapterTopics(@PathVariable("chapter") String chapter){
        List<Answer> answers = ansiElement.chapterTopics(chapter);
        return Result.ok(answers);
    }

    /**
     * 作用: 错误题
     * yinj on 2023/7/7
     * @param
     * @return Result
    **/
    @RequestMapping("wrongtopic")
    public Result wrongtopic(){
        List<Answer> answers = ansiElement.wrongtopic();
        return Result.ok(answers);
    }

    /**
     * 作用: 做题
     * yinj on 2023/7/7
     * @param answer 传 id，answer
     * @return Result
    **/
    @RequestMapping("exercises")
    public Result exercises(Answer answer){
        boolean answers = ansiElement.exercises(answer);
        return Result.ok(answers);
    }

    /**
     * 作用: 首页，查总题和错误题
     * yinj on 2023/7/8
     * @param
     * @return Result
    **/
    @RequestMapping("homepage")
    public Result homepage(){
       HashMap<String,Integer> map = ansiElement.homepage();
       return Result.ok(map);
    }

    /**
     * 作用: 章节列表
     * yinj on 2023/7/8
     * @param
     * @return Result
    **/
    @RequestMapping("chapterLists")
    public Result chapterLists(){
        List<HashMap<String,Object>> map = ansiElement.chapterLists();
        return Result.ok(map);
    }

}
